@extends('Admin.layouts.common')

@section('content')
    <div class="container myContainer">
        <button class="btn btn-info searchBtn" onclick="$('.search_box').slideToggle();">搜索/筛选</button>
        <div class="search_box">
            <form id="search_form" method="GET">
                <label>
                    标题：<br>
                    <input name="key" type="text" class="form-control search_form_control" value="{{ $_search['key'] }}">
                </label>
                <label>
                    分类：<br>
                    <select name="type" class="form-control search_form_control">
                        <option value="">全部</option>
                        @foreach($cats as $cat_id=>$item)
                        @if($cat_id>0)
                        <option value="{{$cat_id}}" @if($_search['type']==$cat_id) selected="" @endif>{{$item->name}}</option>
                        @endif
                        @endforeach
                    </select>
                </label>
                <button class="btn btn-primary" type="submit">&nbsp;&nbsp;确定&nbsp;&nbsp;</button>
            </form>
        </div>

        <div class="table-responsive">
            <table class="table">
                <caption>待审核视频列表({{$list->total()}})</caption>
                <thead>
                    <tr>
                        <th><button onclick="batch_refund()" class="btn btn-info">批量拒绝</button>#</th>
                        <th>图片</th>
                        <th>标题</th>
                        <th>分类</th>
                        <th>显示PV</th>
                        <th>添加时间</th>
                        
                        <th>操作</th>
                    </tr>
                </thead>
                <tbody>
                    @forelse($list->items() as $item)
                        <tr id="tr_{{$item->id}}">
                            <td>
                                <input type="checkbox" name="ids[]" value="{{$item->id}}">
                                {{ $item->id }}</td>
                            <td>
                                @foreach($item->pic as $img)
                                    <img style="max-width:150px" src="{{$img}}" />
                                @endforeach

                            </td>
                            <td><a href="javascript:;" onclick="layx.iframe('{{$item->id}}','{{$item->title}}','/article/video_info/{{$item->id}}',{
    width:400,
    height:400,
    maxMenu:false,
    statusBar:true,
    buttons:[
        {
            label:'通过',
            callback:function(id, button, event){
                // 获取 iframe 页面 window对象
                $.post('/article/ajax_video_adopt/{{$item->id}}',{},function(json){
                    if(json.status==1){
                        $('#tr_'+id).fadeOut();
                    }else{
                  
                    }
                },'json');
                layx.destroy(id);
            }
        },
        {
            label:'不通过',
            callback:function(id, button, event){
                $.post('/article/ajax_video_refund/{{$item->id}}',{},function(json){
                    if(json.status==1){
                        $('#tr_'+id).fadeOut();
                    }else{
                  
                    }
                },'json');
                layx.destroy(id);
            }
        }
    ]
});" > 
@if(empty($item->format_title))
                                {{$item->title}}
                                @else
                                {!! $item->format_title !!}
                                @endif
</a></td>
                            <td id="cat_{{$item->id}}">{{ $item->cat_name }}</td>
                            <td>{{$item->show_pv}}</td>
                            <td>{{ date('Y-m-d H:i:s',$item->day) }}</td>
                            <td>
                                <select class="form-control search_form_control" onchange="set_cat({{$item->id}},this)">
                                   @foreach($cats as $cat_id=>$line)
                                    <option value="{{$cat_id}}" @if($cat_id==$item->type) selected="" @endif>{{$line->name}}</option>
                                    @endforeach 
                                </select>
                                <!--<a href="http://www.{{ env('APP_URL') }}/home/article/{{ $item->id }}" target="_blank">查看</a>
                                <a href="/Theme/edit/{{ $item->id }}">编辑</a>
                                <a href="javascript:;" onclick="ajax_delete_theme(<?=$item->id?>)">删除</a>
                                -->
                            </td>
                        </tr>
                    @empty
                        <tr><td class="text-center" colspan="7">没有数据</td></tr>
                    @endforelse
                </tbody>
            </table>
            <div class="text-center">
                <div style="float: left;"><button onclick="batch_refund()" class="btn btn-info">批量拒绝</button></div>
                {{ $list->links() }}
            </div>
        </div>

    </div>
@endsection

@section('foot')
<script type="text/javascript">
$.ajaxSetup({
    headers: {
    'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
    }
})

function ajax_delete_theme(id){
    if(confirm('确认删除吗?')){
        $.post("/theme/ajax_delete_theme/"+id,{},function(json){
            if(json.status==1){
                $("#tr_"+json.data).fadeOut();
            }else{
                alert(json.info);
            }
        },"json");
    }
}
function set_cat(id,obj){
    var type = $(obj).val();
    var name = $(obj).find("option:selected").text();
    $("td#cat_"+id).text(name);
    $.post('/article/ajax_video_set_cat/'+id,{type:type},function(json){
    
    },"json");
}

function batch_refund(){
    var a = $("input[name='ids[]']:checked").length;
    if(a==0){
        alert("请选择要拒绝的文章");
        return false;
    }
    var ids = "";
    $("input[name='ids[]']:checked").each(function(i){
        if (i == 0) {
            ids = this.value;//循环每个值
        } else {
            ids += "," + this.value;
        }
    });
    if(confirm("您选择了"+a+"个项目，确定要批量拒接吗？")){
        $.post("/article/ajax_video_batch_refund",{ids:ids},function(json){
            if(json.status==1){
                window.location.reload();
            }else{
                alert("error");
            }
        },"json");
    }
}
</script>
@endsection